﻿using MongoDB.Driver;
using Sustainalytics.Entities.RiskRatings;
using System.Threading.Tasks;

namespace Sustainalytics.ClientDW.Synchronization.SyncRiskRatingsData.Indexes
{
    public class RiskRatingResearchProfileIndexes
    {
        public static async Task RecreateIndexes(IMongoCollection<RiskRatingResearchProfile> collection)
        {            
            await collection.Indexes.CreateOneAsync(Builders<RiskRatingResearchProfile>.IndexKeys.Ascending(x => x.Id)).ConfigureAwait(false);
            await collection.Indexes.CreateOneAsync(Builders<RiskRatingResearchProfile>.IndexKeys.Ascending(x => x.CompanyId)).ConfigureAwait(false);
            await collection.Indexes.CreateOneAsync(Builders<RiskRatingResearchProfile>.IndexKeys.Ascending(x => x.SubPeerGroupId)).ConfigureAwait(false);
            await collection.Indexes.CreateOneAsync(Builders<RiskRatingResearchProfile>.IndexKeys.Ascending(x => x.Assessment)).ConfigureAwait(false);

            CreateIndexOptions options = new CreateIndexOptions { Collation = new Collation(locale: "en", caseLevel: true, strength: CollationStrength.Primary) };

            await collection.Indexes.CreateOneAsync(Builders<RiskRatingResearchProfile>.IndexKeys.Ascending(x => x.CompanyName), options).ConfigureAwait(false);
            await collection.Indexes.CreateOneAsync(Builders<RiskRatingResearchProfile>.IndexKeys.Ascending(x => x.Exchange), options).ConfigureAwait(false);
            await collection.Indexes.CreateOneAsync(Builders<RiskRatingResearchProfile>.IndexKeys.Ascending(x => x.Ticker), options).ConfigureAwait(false);
            await collection.Indexes.CreateOneAsync(Builders<RiskRatingResearchProfile>.IndexKeys.Ascending(x => x.SubPeerGroup), options).ConfigureAwait(false);
            await collection.Indexes.CreateOneAsync(Builders<RiskRatingResearchProfile>.IndexKeys.Ascending(x => x.LastUpdate), options).ConfigureAwait(false);
        }
    }
}
